package com.one.blocks.rbac.controller.convert.worker;

import com.one.blocks.rbac.controller.vo.SysMenuVo;
import com.one.blocks.rbac.domain.SysMenu;
import com.one.blocks.rbac.manager.SysMenuManager;
import org.mapstruct.Named;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author linfuxin Created on 2022-04-25 14:51:42
 */
@Component
public class SysMenuQualifier {

    @Autowired
    public SysMenuManager sysMenuManager;

    @Named(value = "levelNum")
    public Integer levelNum(SysMenuVo sysMenuVo) {
        if (sysMenuVo == null) {
            return 1;
        }
        if (sysMenuVo.getLevelNum() != null) {
            return sysMenuVo.getLevelNum();
        }
        Integer parentId = sysMenuVo.getParentId();
        if (parentId == null) {
            return 1;
        }
        SysMenu sysMenu = sysMenuManager.get(parentId);
        return sysMenu == null ? 1 : sysMenu.getLevelNum() + 1;
    }
}
